<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo" placeholder="请输入订单编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-input v-model="model.type" placeholder="请输入订单类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seedName">
              <a-input v-model="model.seedName" placeholder="请输入品种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入产品名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仓库id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="houseId">
              <a-input v-model="model.houseId" placeholder="请输入仓库id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货仓库名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="houseName">
              <a-input v-model="model.houseName" placeholder="请输入发货仓库名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品运输数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productNum">
              <a-input-number v-model="model.productNum" placeholder="请输入产品运输数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货人id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendUserId">
              <a-input v-model="model.sendUserId" placeholder="请输入发货人id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendUser">
              <a-input v-model="model.sendUser" placeholder="请输入发货人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendMobile">
              <a-input v-model="model.sendMobile" placeholder="请输入发货人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendAddress">
              <a-input v-model="model.sendAddress" placeholder="请输入发货地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveUser">
              <a-input v-model="model.receiveUser" placeholder="请输入收货人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveMobile">
              <a-input v-model="model.receiveMobile" placeholder="请输入收货人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveAddress">
              <a-input v-model="model.receiveAddress" placeholder="请输入收货地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <a-input v-model="model.state" placeholder="请输入状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'WmsOrderForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           orderNo: [
              { required: true, message: '请输入订单编号!'},
           ],
           type: [
              { required: true, message: '请输入订单类型!'},
           ],
           productName: [
              { required: true, message: '请输入产品名称!'},
           ],
        },
        url: {
          add: "/seedexpress/wmsOrder/add",
          edit: "/seedexpress/wmsOrder/edit",
          queryById: "/seedexpress/wmsOrder/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>